#!/bin/python
import time
import re
import glob
import serial

comp = re.compile(r'^c=\s*(\d+), PWM=\s*(\d+), I=\s*(\d+), U=\s*(\d+), R=\s*(\d+)\n$')

class DLT:
    def __init__(self, tty=None):
        if tty is None:
            tty = glob.glob('/dev/ttyUSB*')[0]
        self.ser = serial.Serial(tty, baudrate=460800, timeout=60)

    def read(self):
        s = self.ser.read(44).decode()
        ts = time.time()
        groups = comp.match(s).groups()
        return ts, *map(lambda x:int(x), groups)


if __name__ == '__main__':
    dlt = DLT()
    while True:
        print(dlt.read())
